package cn.ywsj.ywsjmidtier.service.impl;


import cn.ywsj.ywsjmidtier.entity.GoodsDe;
import cn.ywsj.ywsjmidtier.entity.GoodsDetails;
import cn.ywsj.ywsjmidtier.entity.InterfaceTrans;
import cn.ywsj.ywsjmidtier.entity.VO.*;
import cn.ywsj.ywsjmidtier.mapper.InterfaceTransMapper;
import cn.ywsj.ywsjmidtier.service.GoodsService;
import cn.ywsj.ywsjmidtier.service.InterfaceTransService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class InterfaceTransServiceImpl extends ServiceImpl<InterfaceTransMapper, InterfaceTrans> implements InterfaceTransService {

    @Autowired
    private InterfaceTransMapper transMapper;

    @Autowired
    private InterfaceTransService service;

    @Autowired
    private GoodsService goodsService;

    @Override
    public Map<String, Object> queryInterfaceTrans() {
        Map<String, Object> map = new HashMap<>();
        InterfaceTrans trans = transMapper.selectById(1);
        String json = trans.getMappingValue();
        //mappingValue
        JSONObject jsonObject = JSONObject.parseObject(json, JSONObject.class, Feature.OrderedField);
        //javaShop
        List<GoodsDe> list = new ArrayList<>();
        list = JSONObject.parseArray(goodsService.getGoods().toString(),GoodsDe.class);
        JSONObject jsonObject2 = JSONObject.parseObject(JSONObject.toJSONString(list.get(0)),JSONObject.class, Feature.OrderedField);
        //xsx
        ProductViewVo productViewVo = new ProductViewVo();
        if(!jsonObject2.isEmpty()){
            for(Map.Entry<String,Object> entry : jsonObject.entrySet()){
                for(Map.Entry<String,Object> entry1 : jsonObject2.entrySet()){
                    if(entry.getKey() == entry1.getKey()){
                        if(Objects.isNull(productViewVo.getProductId())){
                            productViewVo.setProductId(Long.parseLong(entry1.getValue().toString()));
                           /* List<ProductSkuValueViewVo> productSkuValueList = productViewVo.getProductSkuValueList();
                            for (ProductSkuValueViewVo productSkuValueViewVo : productSkuValueList) {
                                productSkuValueViewVo.setProductId(Long.parseLong(entry1.getValue().toString()));
                            }*/
                            continue;
                        }
                        if(Objects.isNull(productViewVo.getProductName())){
                            productViewVo.setProductName(entry1.getValue().toString());
                            continue;
                        }
                        if(Objects.isNull(productViewVo.getProductPrice())){
                            productViewVo.setProductPrice(Double.parseDouble(entry1.getValue().toString()));
                            break;
                        }
                    }
                }
            }
        }
        map.put("unit",new DataParameterViewVo());
        map.put("productViewVo",productViewVo);
        map.put("companyViewVo",new CompanyViewVo());
        map.put("freeDelivery",null);
        map.put("attachViewVo",new DataParameterViewVo());
        map.put("productAttrListViewVo",new ProductAttrListViewVo());
        return map;
    }

    public static void main(String[] args) {
        InterfaceTransServiceImpl service = new InterfaceTransServiceImpl();
        System.out.println(service.queryInterfaceTrans());
    }
}
